﻿using IterationLife.UserProfiles.Models;
using Util.Datas.Ef;

namespace IterationLife.Datas.Mappings.UserProfiles {
    /// <summary>
    /// 用户亲属映射配置
    /// </summary>
    public class UserRelativeMap : AggregateRootMapBase<UserRelative> {
        /// <summary>
        /// 映射表
        /// </summary>
        protected override void MapTable() {
            ToTable( "UserRelatives", "UserProfiles" );
        }
        
        /// <summary>
        /// 映射属性
        /// </summary>
        protected override void MapProperties() {
            //用户亲属编号
            Property(t => t.Id)
                .HasColumnName("UserRelativeId");
        }
        
        /// <summary>
        /// 映射导航属性
        /// </summary>
        protected override void MapAssociations() {
            //用户资料
            HasRequired(t => t.UserProfile)
                .WithMany(t => t.UserRelatives)
                .HasForeignKey(d => d.UserProfileId);
            //用户
            HasRequired(t => t.User)
                .WithMany()
                .HasForeignKey(d => d.UserId);
        }
    }
}
